package com.guaoran.source.mybatis.v2.execute;

import com.guaoran.source.mybatis.v2.config.Configuration;
import com.guaoran.source.mybatis.v2.plugin.InterceptorChain;

/**
 * @author : 孤傲然
 * @Description :
 * @date :2018/5/26 22:11
 */
public class ExecutorFactory {
    private static final String DEFAULT = "default";
    private static final String CACHE = "cache";
    private static InterceptorChain interceptorChain;
    public static Executor getExecutor(String key, Configuration configuration) {
        interceptorChain = configuration.getInterceptorChain();
        Executor executor = new DefaultExecutor(configuration);
        if(CACHE.equalsIgnoreCase(key)){
            executor = new CacheExecutor(new DefaultExecutor(configuration));
        }else{}
        executor = (Executor) interceptorChain.pluginAll(executor);
        return executor;
    }

    public enum ExecutorType {
        DEFAULT,CACHE
    }

}